#include "iostream"
#include "math.h"
#include <iterator>
#include <QtConcurrentMap>
#include <QFuture>
#include <QFutureIterator>
#define N 1000
#define A 0
#define B (3.1415926)


double f(double arg) {
    return sin(arg);
}

double mapFunction(double a) {
    return f(a) * (B - A) / N;
}


void reduceFunction(double &result, double const& mapResult) {
    result += mapResult;
}


int main() {
    double points[N];
    for(int i = 0; i < N; ++i) {
        points[i] = A + (i * (B - A)) / N;
    }

    std::cout << QtConcurrent::blockingMappedReduced(points,
                                        points + N,
                                        mapFunction,
                                        reduceFunction,
                                        QtConcurrent::UnorderedReduce) << std::endl;
}
